package esb.logger;

import java.io.*;

import org.apache.log4j.Logger;

import jpa.entities.ClientBestelling;

public class WriteConfirmToDisk {

	/**
	 * @param args
	 * @throws Exception 
	 */
	private static Logger logger = Logger.getLogger(WriteConfirmToDisk.class);
	
	public String enhance(String payload) {
		int pos = payload.lastIndexOf("@");
		int bestelID = Integer.parseInt(payload.substring(pos + 1,
				payload.length()));
		String message = payload.substring(0, pos);

		System.out.println("Confirm message: " + message
				+ " opgeslagen onder naam: " + bestelID + ".txt");

		try {
			Writer output = null;
			File file = new File("C:\\uitvoer\\"+bestelID+".txt");
			output = new BufferedWriter(new FileWriter(file));
			output.write(message);
			output.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		System.out.println("Bestelling weggescreven naar hardeschijf");
		logger.info(message);
		return payload;
	}

}
